// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';


Vue.config.productionTip = false
// 使用elementui
Vue.use(ElementUI);

// 将axios依赖绑定到vue实例上 可以通过 $http发送请求
Vue.prototype.$http=axios
axios.defaults.baseURL="http://localhost:9021/"

//请求拦截器
axios.interceptors.request.use(req=>{
  // console.log("123")
  req.headers['token']=localStorage.getItem('token');

return req;
});
// 响应拦截器
axios.interceptors.response.use(resp=>{
  if(resp.data.code==401){
    router.push('/login')
  }else{
    if(resp.headers['token']){
       // console.log("456")
     localStorage.setItem('token',resp.headers['token']);
    }
  }
return resp;
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
